package com.rf.richfitwheel.sysbill.controller;


import com.rf.richfitwheel.admin.utils.UserUtil;
import com.rf.richfitwheel.sysbill.model.SysBillAccount;
import com.rf.richfitwheel.sysbill.service.SysBillAccountService;
import com.rf.richfitwheel.utils.PageJson;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangTao
 * @since 2024-06-17
 */
@RestController
@RequestMapping("/sysbill/sysBillAccount")
@Api(tags = "基础数据设置--电票账户",description = "提供电票信息的相关的API",value = "SysBillAccount类")
public class SysBillAccountController {

    @Autowired
    private SysBillAccountService sysBillAccountService;

    /**
     * 通过ID查询信息
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "根据ID查询电票单条信息")
    public SysBillAccount detail(@ApiParam(name = "id",required = true) @PathVariable("id")  String id) {
        QueryWrapper<SysBillAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        SysBillAccount sysBillAccount = sysBillAccountService.getOne(queryWrapper);
        return sysBillAccount;
    }

    @GetMapping("/deleteOne/{id}")
    @ApiOperation(value = "根据ID查询删除单条电票信息")
    public Boolean deleteOne(@ApiParam(name = "id",required = true)@PathVariable("id") String id) {
        return sysBillAccountService.removeById(id);
    }

    /**
     * 分页查询信息
     *
     * @param
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "电票数据分页查询信息")
    public PageJson getPageList(@RequestBody SysBillAccount sysBillAccount) {
        PageJson pageJson = sysBillAccountService.pageJson(sysBillAccount);
        return pageJson;
    }

    /**
     * 添加
     * @param sysBillAccount
     * @return
     */
    @PostMapping("/add")
    @ApiOperation( value = "新增电票数据单条信息")
    public boolean save(@RequestBody SysBillAccount sysBillAccount) {
        //直联状态 1:启用 2:停用   新添加的默认是启用
        sysBillAccount.setBankStatus("1");
        //创建人
        sysBillAccount.setCreateName(UserUtil.getUser().getStaffName());
        return sysBillAccountService.save(sysBillAccount);
    }

    /**
     * 修改
     * @param sysBillAccount
     * @return
     */
    @PostMapping("/modify")
    @ApiOperation( value = "修改电票数据单条信息")
    public boolean modify(@RequestBody SysBillAccount sysBillAccount) {
        return sysBillAccountService.updateById(sysBillAccount);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PostMapping("/del")
    @ApiOperation( value = "删除电票数据多条信息")
    public boolean delBatch(@ApiParam(name = "ids",required = true) @RequestParam("ids") List<String> ids) {
        return sysBillAccountService.removeByIds(ids);
    }
}
